const Orders = require('../model/order.model')

class OrderService {
    async createOrder(order) {
        return await Orders.create(order)
    }

    async findAllOrder(pageNum, pageSize, status) {
        const { count, rows } = await Orders.findAndCountAll({
            attributes: ['goods_info', 'total', 'order_number', 'status'],
            where: {
                status
            },
            offset: (pageNum - 1) * pageSize,
            limit: pageSize * 1
        })

        return {
            pageNum,
            pageSize,
            total: count,
            list: rows
        }
    }

    async updateOrder(id, status) {
        return await Orders.update({ status }, { where: { id } })
    }
}

module.exports = new OrderService()